﻿import java.sql.*;
public class MySql3  {
    public static void main(String[] args) {
        Connection con;
        Statement sql;
        ResultSet rs;
        con = GetDBConnection.connectionDB("world","root","");
        if(con==null) {
            return;
        }
        try{
            sql = con.createStatement();
            rs = sql.executeQuery("SELECT * FROM country where LifeExpectancy!=0 order by LifeExpectancy");
            rs.first();
            System.out.println("世界上的平均寿命最短的国家是:"+rs.getString(2)+
                    ",平均寿命为："+rs.getInt(8));
            rs.last();
            System.out.println("世界上的平均寿命最长的国家是:"+rs.getString(2)+
                    ",平均寿命为："+rs.getInt(8));
            con.close();
        }catch (SQLException e){
            System.out.println(e);
        }

    }
}
